<template>

	<view class="uni-list">
		<view class="uni-list-row">
			{{user.test}}
		</view>
		
		<view class="uni-list-row" hover-class="uni-list-row-hover" v-for="(item,key) in contacts" @click="to_chat(item)" :key="key">
			{{item.title}}
		</view>
	</view>

</template>

<script>
	
	import contact from './main.js'
	
	import {
		mapState
	} from 'vuex'
	
	var windows = {
		store: null
	};

	export default {

		data() {
			return {
				contacts: []
			};
		},
		onShow: function () {
			console.log('a App Show')
		},
		onHide: function () {
			console.log('a App Hide')
		},
		
		computed: mapState(['user']),

		created: function () {
			
			let that = this;
			
			contact.getContacks(function (e) {
				that.contacts = e;
			});
			
			windows.store = that.$store.state;
			
			
		},

		methods: {
			
			to_chat: function (item) {
				
				console.log(JSON.stringify(item))
				
				plus.webview.create('https://app.help-itool.com/Page/sesstion/View/Im/chat/i.html','iSesstion',null,{
					
					// 会话名称
					title:item.title,
					
					// 对方 UserKey [type long]
					toUserKey:item.mobile,
					
					// 头像
					headImg: 'https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=3400163923,2373757593&fm=173&app=25&f=JPEG?w=550&h=413&s=F29B1DC74EA34E96EB11E9DF03009097',
					
					// [0|1]可选 0点对点，1群组会话
					sessionType:0 
				});
				

				
				return;
				
				// 下载
				uni.downloadFile({
					url: 'https://www.help-itool.com//Content/app/init.js', //仅为示例，并非真实的资源
					success: function (res) {
						if (res.statusCode === 200) {
							
							console.log('下载成功');
							console.log(JSON.stringify(res))
							
							uni.saveFile({
								tempFilePath: res.tempFilePath,
								success: function (res) {
									var savedFilePath = res.savedFilePath;
									console.log(res.savedFilePath)
									var webview = plus.webview.create('http://renjian.163.com/', 'asd');
									webview.setJsFile(savedFilePath);
									webview.show('slide-in-right')
								}
							});
							
						}
					}
				});

			}
		}

	}
</script>

<style>
	.uni-list {
		width: 100%;
		display: flex;
		flex-direction: column;
	}

	.uni-list-row {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		padding: 20px 16px;
		border-bottom: #F7F5F6 solid 1px;
	}

	.uni-list-row-hover {
		background-color: #F7F5F6;
	}
</style>
